<template>
	<!--新增对话框-->
	<el-dialog
		:title="editForm.id ? '编辑' : '新增'"
		:visible.sync="dialogVisible"
		width="500px"
		:before-close="handleClose"
    top="5vh"
	>
		<el-form :model="editForm" :rules="editFormRules" ref="editForm">
			<el-form-item label="报告时间" prop="month" label-width="150px">
        <el-date-picker
          v-model="editForm.date"
          type="month"
          disabled
          value-format="yyyy.MM"
          placeholder="选择年月">
        </el-date-picker>
			</el-form-item>
      <el-form-item label="新船价格指数" prop="new_ship" label-width="150px">
        <el-input-number v-model="editForm.new_ship" size="medium" :precision="2" :step="0.01" :min="0"></el-input-number>
      </el-form-item>
      <el-form-item label="二手船价格指数" prop="second_ship" label-width="150px">
        <el-input-number v-model="editForm.second_ship" size="medium" :precision="2" :step="0.01" :min="0"></el-input-number>
      </el-form-item>
		</el-form>
		<div slot="footer" class="dialog-footer">
			<el-button @click="resetForm('editForm')">取 消</el-button>
			<el-button type="primary" @click="submitForm('editForm')">确 定</el-button>
		</div>
	</el-dialog>
</template>

<script>
import {formatServerDate, monthFormatStr} from '@/utils/date';
import { isNumber } from '@/utils/validate';
export default {
	name: 'AddUpdateShipPrice',
	components: {},
	data() {
		return {
			editForm: {},
			loading: false,
			dialogVisible: false,
			editFormRules: {
				new_ship: [{ required: true, message: '请输入新船价格指数', trigger: 'blur' }],
        second_ship: [{ required: true, message: '请输入二手船价格指数', trigger: 'blur' }],
			},
		};
	},
	mounted() {
		// this.getFarmList('');
	},

	methods: {
		resetForm(formName) {
			this.$refs[formName].resetFields();
			this.dialogVisible = false;
			this.editForm = {};
		},
		handleClose() {
			this.resetForm('editForm');
		},
		submitForm(formName) {

			this.$refs[formName].validate((valid) => {
				if (valid) {
          const {date, ...rest} = this.editForm;
					this.$axios
						.get('/admin/boat/ship/price/' + (this.editForm.id ? 'edit' : 'edit'), 
            {
              params: {
              ...rest,
              },
            }).then((res) => {
							this.$message({
								showClose: true,
								message: '恭喜你，操作成功',
								type: 'success',
								onClose: () => {
									this.$emit('refreshDataList');
								},
							});
							this.dialogVisible = false;
							this.resetForm(formName);
						});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		checkIsDisabledDate(date){
			console.log(date);
			return true;
		},
		init(id) {
			this.dialogVisible = true;
			if (id != null && id != '' && id > 0) {
				this.$axios.get('/admin/boat/ship/price/detail?id=' + id).then((res) => {
          const {result = {}} = res;
          const { id, date,...rest} = result;
          this.editForm = {
              id: id,
              date: formatServerDate(date, monthFormatStr),
              ...rest,
          };
				});
			}
		},
	},
};
</script>

<style scoped>
.avatar-uploader .el-upload {
	border: 1px dashed #d9d9d9;
	border-radius: 6px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
}
.avatar-uploader .el-upload:hover {
	border-color: #409eff;
}
.avatar-uploader-icon {
	font-size: 28px;
	color: #8c939d;
	width: 178px;
	height: 178px;
	line-height: 178px;
	text-align: center;
}
.avatar {
	width: 178px;
	height: 178px;
	display: block;
}
</style>
